package com.htg.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;


public class DialogTaskCompleteState {

    private Context cxt;

    private AlertDialog alertDialog = null;


    public DialogTaskCompleteState(Context cxt) {
        this.cxt = cxt;
    }

    public void show(int allsize, int unchecksize, int checksize) {
        if (alertDialog == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(cxt);
            alertDialog = builder.create();
        } else {
            if (alertDialog.isShowing()) {
                return;
            }
        }
        alertDialog.show();
        View view = LayoutInflater.from(cxt).inflate(R.layout.dialog_task_complete_state, null);
        Window window = alertDialog.getWindow();
        window.setBackgroundDrawableResource(R.drawable.shape_white_rounded_12dp);
        WindowManager.LayoutParams params = window.getAttributes();
        int width = cxt.getResources().getDimensionPixelSize(R.dimen.dp_280);

        params.width =  width;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);
        //window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.WRAP_CONTENT);
        window.setContentView(view);

        TextView tvAllsize = view.findViewById(R.id.tv_dialog_taskcompletestate_allsize);
        TextView tvUnchecksize = view.findViewById(R.id.tv_dialog_taskcompletestate_unchecksize);
        TextView tvCheckSize = view.findViewById(R.id.tv_dialog_taskcompletestate_checksize);
        TextView tvOk = view.findViewById(R.id.tv_dialog_taskcompletestate_ok);

        tvAllsize.setText(String.valueOf(allsize));
        tvUnchecksize.setText(String.valueOf(unchecksize));
        tvCheckSize.setText(String.valueOf(checksize));

        tvOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
            }
        });

    }


    public void dismis() {
        if (alertDialog != null && alertDialog.isShowing()) {
            alertDialog.dismiss();
        }
        alertDialog = null;
    }


}
